<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <link href="__PUBLIC__/css/Content/index.css" rel="stylesheet" type="text/css" />
    <style>
        #dg{
            height: 100%;;
        }
    </style>
</block>
<block name="bdoy">
    <body>
    <table id="dg"></table>

    <div id="toolbar" style="padding:5px;height:auto">
        <div style="margin-bottom:5px">
            <a href="#" id="print_button" class="easyui-linkbutton" iconCls="icon_ext icon-magic" plain="true">打印</a>
            <a href="#" id="add_button" class="easyui-linkbutton" iconCls="icon-add" plain="true">{:LANG('add')}</a>
            <a href="#" id="edit_button" class="easyui-linkbutton" iconCls="icon-edit" plain="true">{:LANG('edit')}</a>
            <a href="#" id="del_button" class="easyui-linkbutton" iconCls="icon-remove" plain="true">{:LANG('del')}</a>
            <a href="#" id="search_button" class="easyui-linkbutton" iconCls="icon-search" plain="true">{:LANG('search')}</a>
            <a href="#" id="reload_button" class="easyui-linkbutton" iconCls="icon-reload" plain="true">{:LANG('reload')}</a>
            <!--            <a href="#" id="clear_button" class="easyui-linkbutton" iconCls="icon-redo" plain="true">{:LANG('clearSelections')}</a>-->
<!--            <a id="bz_export" href="#" class="easyui-linkbutton"  onclick="export_xls()" iconCls="icon-xls" plain="true">导出故障报表</a>-->
        </div>
        <div id="queryMaterialsRemovalParamZone">
            <form id="query_form" method="post" action="">
                <table>
                    <tr>
                        <td>泵站/调蓄池</td>
                        <td><input type="text" class="" name="station" width="100"/></td>
                        <td>设备名称</td>
                        <td><input type="text" class="" name="name" width="100"/></td>
                        <td>处理状态</td>
                        <td><select name="status">{:fix_status()}</select></td>

                        <td><a id="query_button" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                        <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#query_form').form('clear');">重置</a></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>

    <div id="fixlogDlg" class="easyui-dialog" title="" style="width:650px;height:500px;padding:10px" buttons="#dlg-buttons-fix-log" closed="true" resizable="true">
        <form id="fixlogForm" method="post" action="">
            <input id="saveflag_fix_log" name="saveflag_fix_log" type="hidden" value="add"/>
            <input id="pump_id" type="hidden" name="id" />
            <input id="csdtstationid_gate_log" type="hidden" name="gateid" />
            <table border="0">
                <tr>
                    <td align="right">编号 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="record_index" style="width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">维修情况 ：</td>
                    <td>
                        <select class="easyui-combobox" name="status" style="width:240px;" required="true" editable="false">
                            {:fix_status()}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">泵站/调蓄池 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="station" style="width: 240px;" required="true"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">泵站电话 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="phone" style="width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">报修人 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="opr" style="width: 240px;" required="true"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">报修时间 ：</td>
                    <td>
                        <input class="easyui-datetimebox" type="text" name="report_time" style="width: 240px;" required="true" editable="false"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">设备简介 ：</td>
                    <td>
                        <input class="easyui-textbox" data-options="multiline:true" type="text" name="name" style="height: 50px;width: 240px;" required="true"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">故障描述 ：</td>
                    <td>
                        <input class="easyui-textbox" data-options="multiline:true" type="text" name="content" style="height: 80px;width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">维修组 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="fix_group" style="width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">组长 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="fix_group_leader" style="width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">维修人员 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="fix_persons" style="width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">值守人员 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="gard_person" style="width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">维修时间 ：</td>
                    <td>
                        <input class="easyui-datetimebox" type="text" name="fixtime" style="width: 240px;" editable="false"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">修复时间 ：</td>
                    <td>
                        <input class="easyui-datetimebox" type="text" name="endtime" style="width: 240px;" editable="false"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">故障原因 ：</td>
                    <td>
                        <input class="easyui-textbox" data-options="multiline:true" type="text" name="error_reason" style="height: 80px;width: 240px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">更换配件 ：</td>
                    <td>
                        <input class="easyui-textbox" data-options="multiline:true" type="text" name="change_fy" style="height: 80px;width: 240px;"></input>
                    </td>
                </tr>

            </table>
        </form>
    </div>
    <div id="dlg-buttons-fix-log" style="text-align: center;">
        <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submitfixlogForm();">保存</a>
    </div>
    <div id="gtx_window" class="easyui-window" closed="true" title="导出报表" data-options="modal:true" style="width:300px;height:150px;padding:0px;overflow: hidden;">
        <form id="form">
            <table class="form-table">
                <tr>
                    <td width="100" align="center">起始日期：</td>
                    <td><input id="start_date" class="easyui-datetimebox textbox" required data-options="validType:'md[\'10/11/2012\']',prompt:'{:LANG('pls_slet')}{:LANG('start_date')}'"></td>
                </tr>
                <tr>
                    <td width="100" align="center">结束日期：</td>
                    <td><input id="end_date" class="easyui-datetimebox textbox" required data-options="validType:'md[\'10/11/2012\']',prompt:'{:LANG('pls_slet')}{:LANG('end_date')}'"></td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <a href="javascript:download_xls()" class="easyui-linkbutton" style="width:120px">{:LANG('export')}</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    </body>
</block>
<block name="footExtendJs">
    <script type="text/javascript">
        $(function(){
            var request_url = '__URL__/get_all';
            var add_title = '{:LANG('add')}';
            var edit_title = '{:LANG('edit')}';
            jQuery('#dg').datagrid({
                fit:true,
                nowrap: false,
                striped: true,
                collapsible:false,
                url:request_url,
                queryParams:{page:1,rows:20},
                method:'get',
                pageNumber:1,
                pageSize:20,
                pageList:[20,50,100,200],
                idField:'id',
                    remoteSort: false,
                    columns:[[
                    {field:'ck',title:'', width:80,checkbox:true,align:'center'},
                    {field:'id',title:'ID', width:80,align:'center',hidden:true},
                    {field:'status_text',title:'维修情况', width:120,align:'center'},
                    {field:'station',title:'泵站/调蓄池', width:120,align:'center'},
                    {field:'name',title:'设备', width:120,align:'center'},
                    {field:'report_time',title:'报修时间', width:150,align:'center'},
                    {field:'fixtime',title:'维修时间', width:150,align:'center'},
                    {field:'endtime',title:'完成时间', width:150,align:'center'},
                    {field:'content',title:'维修内容', width:250,align:'center'},
                ]],
                pagination:true,
                rownumbers:true,
                singleSelect:false,
                toolbar: '#toolbar',
                rowStyler: function(index,row){
                    if (row.status == 1){
                        return 'background:#ff0000;';
                    }else if(row.status == 2){
                        return 'background:#EEEE00;';
                    }
                },
                onDblClickRow: function(rowIndex, rowData) {

                },
                onSelect: function(rowIndex, rowData) {
                    var now_rows = jQuery('#dg').datagrid('getSelections');
                    if(now_rows.length > 1){
                        $("#edit_button").linkbutton('disable');
                    }
                },
                onUnselect: function(rowIndex, rowData) {
                    var now_rows = jQuery('#dg').datagrid('getSelections');
                    if(now_rows.length < 2){
                        $("#edit_button").linkbutton('enable');
                    }
                },
                onDblClickRow: function(rowIndex, rowData) {
                    var selected = $('#dg').datagrid('getSelected');
                    editfixlog(rowData.id);
                },
        });
        //按钮事件绑定
        $('#add_button').click(function(){
            $('#fixlogForm').form('clear');
            $("#saveflag_fix_log").val("add");
            $('#fixlogDlg').dialog({title:'录入维修信息',modal:true});
            $('#fixlogDlg').dialog("open");
        });
            $('#edit_button').click(function(){
                var rows = $('#dg').datagrid('getSelections');
                if(rows.length > 1){
                    $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                    return;
                }
                var obj = jQuery('#dg').datagrid('getSelected');
                if(!obj){
                    msgShow('{:LANG('tips')}', '{:LANG('pls_slet_row')}', 'warning');
                }
                editfixlog(obj.id);
                $('#listDialog').dialog({modal:true});
                $('#listDialog').dialog('open');
                $('#listDialog').dialog('maximize');

            });
        $('#del_button').click(function(){
            var id = jQuery('#dg').datagrid('getSelected');
            if(!id){
                msgShow('{:LANG('tips')}', '{:LANG('pls_slet_row')}', 'warning');
            }
            jQuery.messager.confirm('请确认', '你确定要删除吗？', function(r){
                if (r){
                    var ids = jQuery('#dg').datagrid('getSelections');
                    var s = '';
                    for(var i=0;i<ids.length;i++){
                        s += ids[i].id+',';
                    }

                    $.post("__URL__/deleteArray",{"ids":s}, function(result){
                        result = eval("("+result+")");;
                        if(result.status == 1){
                            $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                        } else if(result == 0){
                            $.messager.show({title:'提示',msg:'删除失败！',showType:'slide'});
                        }

                    });
                }
            });
        });
        $('#search_button').click(function(){
            $('#query_form').toggle();
            $('#dg').datagrid("resize");
        });
        $('#reload_button').click(function(){
            $('#dg').datagrid('load', {});
//                window.location.href = window.location.href;
        });
        $('#reload_clear').click(function(){
            $('#dg').datagrid('clearSelections');
        });

        $('#query_button').click(function(){
            var obj = $('#query_form').serializeJson();
            $('#dg').datagrid('load',obj);
        });
        $('#print_button').click(function(){
            var rows = $('#dg').datagrid('getSelections');
            if(rows.length > 1){
                $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                return;
            }
            var obj = jQuery('#dg').datagrid('getSelected');
            if(!obj){
                msgShow('{:LANG('tips')}', '{:LANG('pls_slet_row')}', 'warning');
            }
            window.open('__URL__/print_fix_record?id='+obj.id);
        });
        });
        $('#query_form').hide();

        function editfixlog(id) {
            if(id!=""){
                $("#saveflag_fix_log").val("update");
            }else{
                clearfixlogForm();
                $("#saveflag_fix_log").val("add");
                return;
            }
            $.ajax({url:"__URL__/get_obj_json",data:{id:id},dataType:"json",success:function(json, textStatus){
                $('#fixlogForm').form('load',{
                    "id": json.id,
                    'record_index':json.record_index,
                    'station':json.station,
                    'phone':json.phone,
                    'opr':json.opr,
                    'report_time':json.report_time,
                    'name':json.name,
                    'content':json.content,
                    'fix_group':json.fix_group,
                    'fix_group_leader':json.fix_group_leader,
                    'fix_persons':json.fix_persons,
                    'fixtime':json.fixtime,
                    'gard_person':json.gard_person,
                    'endtime':json.endtime,
                    'error_reason':json.error_reason,
                    'change_fy':json.change_fy,
                    'date':json.date,
                    'status':json.status,
                });
                $('#fixlogDlg').dialog({title:'编辑维修信息',modal:true});
                $('#fixlogDlg').dialog("open");
                setFormFocus('#fixlogForm');
            },error:function(XMLHttpRequest, textStatus, errorThrown)
            {
                relogin(XMLHttpRequest, textStatus, errorThrown);
            }});
        }

        function submitfixlogForm() {
            if ($('#fixlogForm').form('validate')) {
                var submitflag = $("#saveflag_fix_log").val();
                var url = "";
                if (submitflag === "add")
                    url = "__URL__/add";
                if (submitflag === "update")
                    url = "__URL__/edit";
                $('#fixlogForm').ajaxSubmit({
                    url:url,
                    dataType:'json',
                    success: function(data) {
                        if (data.status==1) {
                            if (submitflag === "add") $('#dg').datagrid('load');
                            if (submitflag === "update") $('#dg').datagrid('reload');
                            $('#fixlogDlg').dialog("close");
                            $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                        }
                        else $.messager.alert('提示','操作失败！','error');
                    }
                });
            }else{
                console.log('no valdate');
            }
        }

        function export_xls(){
            $('#gtx_window').window('open');
        }

        function download_xls(){
            var start = $('#start_date').datetimebox('getValue');
            var end = $('#end_date').datetimebox('getValue');
            var url = '/Manage/AdminFix/export_record?start='+start+'&end='+end;
            window.open(url);
        }

    </script>
</block>
